import 'package:dio/dio.dart';
import 'package:logger/logger.dart';

class LoggingInterceptor extends Interceptor {
  final Logger logger;

  LoggingInterceptor(this.logger);

  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    logger.i('''
🚀 请求开始: ${options.method} ${options.uri}
Headers: ${options.headers}
Query: ${options.queryParameters}
Body: ${options.data}
''');
    super.onRequest(options, handler);
  }

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    logger.i('''
✅ 请求成功: ${response.statusCode} ${response.requestOptions.uri}
Response: ${response.data}
''');
    super.onResponse(response, handler);
  }

  @override
  void onError(DioException err, ErrorInterceptorHandler handler) {
    logger.e('''
❌ 请求错误: ${err.type} ${err.requestOptions.uri}
Error: ${err.error}
Response: ${err.response?.data}
''');
    super.onError(err, handler);
  }
}